<template>
  <div class="app-container">
    <el-row :gutter="20">

      <el-col :span="mainwidth" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

          <el-form-item label="时间类型" prop="status">
            <el-select
              v-model="queryParams.timetype"
              placeholder="时间类型"
              clearable
              size="small"
              style="width: 130px"
            >
              <el-option
                v-for="dict in timetypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="selTime"
              type="daterange"
              :picker-options="pickerOptions"
              range-separator="至"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 260px"
              align="right">
            </el-date-picker>
          </el-form-item>

          <el-form-item label="申请人">
            <el-select v-model="queryParams.create_UserIdArr" multiple clearable  :disabled="clearableBool" placeholder="请选择">
              <el-option
                v-for="item in create_UserIdOption"
                :key="item.user_id"
                :label="item.nick_name"
                :value="item.user_id"
              ></el-option>
            </el-select>
          </el-form-item>

        </el-form>

        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom: -10px;line-height:35px">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-input
                v-model="queryParams.value"
                placeholder="查询值"
                clearable
                size="small"
                style="width: 350px"
                @keyup.enter.native="handleQuery"
              >
                <el-select
                  v-model="queryParams.type"
                  placeholder="查询条件"
                  clearable
                  slot="prepend"
                  style="width: 110px;background-color: transparent;color: black;"
                >
                  <el-option
                    v-for="dict in typeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-input>
            </el-col>
            <el-col :span="1.5">
              <el-form-item label="发货状态" style="margin-bottom: 10px;line-height:35px">
                <el-select v-model="queryParams.SAN_Delivery_Status" multiple clearable placeholder="请选择">
                  <el-option
                    v-for="dict in ShipStateOption"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd()"
                v-hasPermi="['yunze:ShippingApplication:add']"
              >新增
              </el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" v-hasPermi="['yunze:ShippingApplication:list']" @queryTable="getList"
                           :columns="columns"></right-toolbar>
          </el-row>
        </el-form>



        <el-table v-loading="loading" :data="DataList">
          <el-table-column :label="columns[0].label" align="center" prop="SAN_Time" v-if="columns[0].visible"/>
          <el-table-column :label="columns[1].label" align="center"  prop="SAN_CoName" v-if="columns[1].visible"/>
          <el-table-column :label="columns[2].label" align="center" prop="SAN_Sender_Name" v-if="columns[2].visible"/>
          <el-table-column :label="columns[3].label" align="center" prop="SAN_StyID" v-if="columns[3].visible">
            <template slot-scope="scope" >
              {{tools.getDkeyValue(DeliveryTypeOption,scope.row.SAN_StyID)}}
            </template>
          </el-table-column>
          <el-table-column :label="columns[4].label" align="center" prop="SAN_ShiptyID" v-if="columns[4].visible">
            <template slot-scope="scope" >
              {{tools.getDkeyValue(DeliveryMethodOption,scope.row.SAN_ShiptyID)}}
            </template>
          </el-table-column>
          <el-table-column :label="columns[5].label" align="center" prop="SAN_Delivery_Status" v-if="columns[5].visible">
            <template slot-scope="scope" >
              <span :class="getColor(scope.row.SAN_Delivery_Status)">{{tools.getDkeyValue(ShipStateOption,scope.row.SAN_Delivery_Status)}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">

              <el-dropdown>
                <el-button type="primary" size="small">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-hasPermi="['yunze:ShippingApplication:Register']"
                                    @click.native="handleUpdate(scope.row,'Register')">登记
                  </el-dropdown-item>
                  <el-dropdown-item v-hasPermi="['yunze:ShippingApplication:edit']"
                                    @click.native="handleUpdate(scope.row,'Edit')">修改
                  </el-dropdown-item>
                  <el-dropdown-item v-hasPermi="['yunze:ShippingApplication:find']"
                                    @click.native="handleUpdate(scope.row,'Find')">详情
                  </el-dropdown-item>
                  <el-dropdown-item v-hasPermi="['yunze:ShippingApplication:del']"
                                    @click.native="handleDel(scope.row)">删除
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>

              <!-- <el-button
                 size="mini"
                 type="text"
                 icon="el-icon-edit"
                 @click="onPreview(scope.row)"
               >图片查看
               </el-button>-->

            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 新增发货申请 -->
    <el-drawer
      :with-header="false"
      :visible.sync="show_ds"
      :close-on-click-modal="false"
      size="90%">
      <el-scrollbar style="height:1000px;min-height: 100%;">
        <ShooingAdd  ref="shooingAdd"
                    :CustomerOneCategoryOption="CustomerOneCategoryOption"
                     :CustomerTowCategoryOption="CustomerTowCategoryOption"
                     :Large_classification="Large_classification"
                     :Small_classification="Small_classification"
                     :DeliveryTypeOption="DeliveryTypeOption"
                     :DeliverySelectionTypeOption="DeliverySelectionTypeOption"
                     :DeliveryMethodOption="DeliveryMethodOption"
                     :ShippingMethodOption="ShippingMethodOption"
                     :contractNatureOption="contractNatureOption"
                     :firmAccountOption="firmAccountOption"
                     :CourierCompanyOptions="CourierCompanyOptions"
                     :CustomerGradeOption="CustomerGradeOption"
                     :selFindoptions="selFindoptions"
                     :form="form"
                     :getTowClass="getTowClass"
                     :commodity="commodity"
                     :window="window"
                     :CustomerAdd="CustomerAdd"
                     :CustomerEdie="CustomerEdie"
                     :HeadquartersnOrmalOption="HeadquartersnOrmalOption"
                     :SubAdd="SubAdd"
                     :loadingSelOption="loadingSelOption"
                     :show_ds="show_ds"
                     :execute="execute"
                     :Editexecute="Editexecute"
                     @SetObj="SetObj"
                     :SubUpd="SubUpd"
                     :OperationType="OperationType"
        />

        <div style="height: 2000px;"></div>
      </el-scrollbar>

    </el-drawer>

    <!--  发货申请 登记 （快递新增） -->
    <el-drawer
      :with-header="false"
      :visible.sync="show_ds_Register"
      :close-on-click-modal="false"
      size="90%">
      <el-scrollbar style="height:1000px;min-height: 100%;">
        <ShooingRegister  ref="shooingRegister"
                     :Large_classification="Large_classification"
                     :Small_classification="Small_classification"
                     :DeliveryTypeOption="DeliveryTypeOption"
                     :DeliverySelectionTypeOption="DeliverySelectionTypeOption"
                     :DeliveryMethodOption="DeliveryMethodOption"
                     :ShippingMethodOption="ShippingMethodOption"
                     :contractNatureOption="contractNatureOption"
                     :CourierCompanyOptions="CourierCompanyOptions"
                     :Regform="Regform"
                     :getTowClass="getTowClass"
                     :commodity="commodity"
                     :window="window"
                     :CustomerAdd="CustomerAdd"
                     :CustomerEdie="CustomerEdie"
                     :loadingSelOption="loadingSelOption"
                     :show_ds_Register="show_ds_Register"
                     :Editexecute="Editexecute"
                     @SetObj="SetObj"
                     :SubRegister="SubRegister"
        />

        <div style="height: 2000px;"></div>
      </el-scrollbar>

    </el-drawer>




  </div>
</template>


<script>
  import {regionData, regionDataPlus, CodeToText, TextToCode} from 'element-china-area-data';
  import {getList, add,Updinfo,DelInfo,Register} from "@/api/yunze/FHGL/FhglShippingApplication";
  import {ExpressSelDate} from "@/api/yunze/FHGL/FhglExpressDelivery";
  import { Administration} from "@/api/yunze/Dictionaries/type";
  import ShooingAdd from './ShooingAdd';
  import ShooingRegister from './ShooingRegister';
  import {findSalesPartner} from "@/api/yunze/XSGL/customer/customer";



  import tools from "@/utils/yunze/tools";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import {getToken} from "@/utils/auth";


  export default {
    name: "FhglShippingApplication",
    components:{
      ShooingAdd,
      ShooingRegister,
    },
    data() {
      return {
        IsDisabled: true,//是否禁用
        checkAll: false,

        ShooingAdd_show:false,//新增 发货申请是否显示
        FindOption_show: false,//查询商品按钮 显示
        execute:true,//加载是否 已执行
        Editexecute:false,//发货申请 编辑加载是否 已执行
        OperationType:'SubAdd',//子界面执行函数 名称判断
        // 大分类
        Large_classification: [],
        // 小分类
        Small_classification: [],
        //回显展示
        innerDrawer: false,

        loadingSelOption: true,//是否 加载 查询客户信息框
        CustomerOption: [],//根据 查询条件加载的销售客户信息
        PeopleOption: [],//根据 查询条件加载的 客户联系人
        AccountOption: [],//根据 查询条件加载的 客户地址

        Regform:{
          SAN_ID: null,
          SAN_StyID: '1',
          SAN_CoID: null,
          SAN_CoName: null,
          SAN_Recipient_Name: null,
          SAN_Recipient_Tel: null,
          SAN_Recipient_Address: null,
          SAN_Time: tools.gitData(),
          SAN_UserID: null,
          SAN_Sender_Name: null,
          SAN_ShiptyID: '1',
          SAN_FpayType: '1',
          SAN_Tracking_Number: null,
          SAN_Express_Delivery: null,
          SAN_Delivery_Status: null,
          SAN_Delivery_Person: null,
          SAN_Remarks: null,
          IsManualBool: false,//手动填写 bool
          c_party_a_id:null,
          Manual_SAN_Recipient_Address:null,//手动填写 地址
          Manual_SAN_Recipient_Tel:null,//手动填写 收件人电话
          Manual_SAN_Recipient_Name:null,//手动填写 收件人
        },

        form:{
          SAN_ID: null,
          SAN_StyID: '1',
          SAN_CoID: null,
          SAN_CoName: null,
          SAN_Recipient_Name: null,
          SAN_Recipient_Tel: null,
          SAN_Recipient_Address: null,
          SAN_Time: tools.gitData(),
          SAN_UserID: null,
          SAN_Sender_Name: null,
          SAN_ShiptyID: '1',
          SAN_FpayType: '1',
          SAN_Tracking_Number: null,
          SAN_Express_Delivery: null,
          SAN_Delivery_Status: null,
          SAN_Delivery_Person: null,
          SAN_Remarks: null,
          SAN_Shipping_Method: null,
          SAN_Shipping_MethodArr: [],
          IsManual: '0',//手动填写
          IsManualBool: false,//手动填写 bool
          c_party_a_id:null,
          Manual_SAN_Recipient_Address:null,//手动填写 地址
          Manual_SAN_Recipient_Tel:null,//手动填写 收件人电话
          Manual_SAN_Recipient_Name:null,//手动填写 收件人
        },

        CustomerAdd: false,//新增 显示
        CustomerEdie: false,//编辑 显示
        CustomerAccountData_Cache: [],//账户信息 表格 修改时 缓存 最初加载数据
        CustomerAccountData_delArr: [],//账户 数据库 删除的id
        CustomerAccountData: [],//账户信息 表格
        Accounttitle: '',
        Account_show: false,//账户信息 显示
        addAccountBtn: false,
        editAccountBtn: false,
        // 账户信息 map
        Accountform: {
          Cat_ID: null,
          Cat_Name: null,
          Cat_Bank_Name: null,
          Cat_Number: null,
          Cat_CoID: null,
          Cat_User_Name: null,
          Cat_Zip_Code: null,
          Cat_Address: null,
          Cat_atId: '1',
        },

        // 商品表参数
        commodity: {
          Cy_Sort: null,
          Cy_Category: null,
        },
        AccountActiveNames: ['0'],//面板默认 展开 【账号】
        PeopleActiveNames: ['0'],//面板默认 展开 【联系人】

        // 时间查询类型 数据字典
        timetypeOptions: [],
        selTime: '',//时间选择
        //客户联系人 数组

        CustomerPeopleData_delArr: [],//联系人 数据库 删除的id
        CustomerPeopleData_Cache: [],//联系人 表格 修改时 缓存 最初加载数据
        CustomerPeopleData: [

        ],
        //联系人 表格
        Peopletitle: '',
        People_show: false,//账户信息 显示
        CustomerDivide_show: false,//客户划分 显示
        addPeopleBtn: false,
        editPeopleBtn: false,
        //划分联系人
        CtDivideform: {
          sales_id: null,
          CDdeptIdArr: [],
        },

        // 客户联系人 map
        Peopleform: {
          id: null,
          cu_id: null,
          name: null,
          telephone: null,
          qq: null,
          nailed: null,
          email: null,
          remarks: null,
          job_title: null,
          state: '1',
          is_maste: '1',
          gender_id: '0',
        },

        PartnerOption: [],//合伙人
        SalesOption: [],//销售
        clearableBool:false,//申请人是否 禁止选择
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },

        options: regionData,
        selFindoptions: regionDataPlus,//是省市区三级联动数据（带“全部”选项）

        CodeToText: CodeToText,
        TextToCode: TextToCode,

        SelselectedOptions: [],

        images: [],
        sortImages: !this.images ? [] : [].concat(this.images),
        acceptConfig: 'image/jpeg,image/png,image/jpg,image/gif',
        fileList: {},

        url: '',
        srcList: [],


        Divide_show: false,//卡划分
        Dividebtn: true,//商品代理 btn
        //商品代理企业
        treeName: undefined,
        formDivide: {
          dept_id: '',
          user_id: '',
        },

        // 导入参数
        upload: {
          // 是否显示弹出层（导入）
          open: false,
          // 弹出层标题（导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: {Authorization: "Bearer " + getToken()},
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/yunze/productPic/Prdedit",
          Pstr: '',//携带参数
        },

        Is_notAdd: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,


        tools: tools,
        deptCheckStrictly: false,
        deptExpand: true,
        deptNodeAll: false,
        show_ds: false,//详情查看
        show_ds_Register: false,//详情查看 发货登记
        table_Online: [],//在线状态信息gradeIdArr
        DeptOptions: [],// 公司信息
        customize_whether: [],//自定义是否
        HeadquartersOption: [], //  总部门所有人
        HeadquartersnOrmalOption: [], //  总部门所有人 【状态正常 】

        create_UserIdOption:[],//总部门所有人 【状态正常 】[申请人 权限不足时为当前登录用户]
        mainwidth: 24,//宽度
        option_show: false, //公司所属查询
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,

        //主界面数据
        DataList: [],
        //  商品 信息 数据
        CommodityList: [],
        CommodityList_delArr :[],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        // 是否显示弹出层
        open: false,
        // 部门名称
        deptName: undefined,
        // 默认密码
        initPassword: undefined,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        typeOptions: [],
        ShipStateOption: [], //数据字典 发货状态
        DeliveryTypeOption: [], //数据字典 发货类型
        DeliverySelectionTypeOption: [], //数据字典 发货选择类型
        DeliveryMethodOption: [], //数据字典 发货方式
        ShippingMethodOption: [],//数据字典 运费方式
        contractNatureOption: [],  //数据字典 订单合同发货信息 合同性质
        firmAccountOption: [], //数据字典 销售单位信息
        CourierCompanyOptions: [],//数据字典 快递公司信息
        //详情
        window:window,
        // 客户一级分类
        CustomerOneCategoryOption: [],
        // 客户二级分类
        CustomerTowCategoryOption: [],
        // 客户级别
        CustomerGradeOption: [],
        // 客户状态
        customerStateOptions: [],
        CustomerSourceOptions: [],// 客户 来源
        // 查询参数
        queryParams: {
          SAN_Delivery_Status: ['1','2'],
          pageNum: 1,
          pageSize: 10,
          type: null,
          value: null,
          create_UserIdArr:[],
        },

        // 列信息
        columns: [
          {key: 0, label: `日期`, visible: true},
          {key: 1, label: `企业名称`, visible: true},
          {key: 2, label: `发件人`, visible: true},
          {key: 3, label: `发货类型`, visible: true},
          {key: 4, label: `发货方式`, visible: true},
          {key: 5, label: `发货申请状态`, visible: true}
        ],
        // 表单校验
        rules: {}
      };
    },
    created() {
      let str = this.$route.query.str;

      if (str != null && str != '' && str.length > 0) {
        var reg_1 = new RegExp("%2F", "g");
        var reg_2 = new RegExp(" ", "g");
        str = str.replace(reg_1, "/");//转义 /
        str = str.replace(reg_2, "+");//转义 [ ]  》 +
        //console.log(str);
        let jsonobj = JSON.parse(tools.Decrypt(str));
        if (jsonobj != null && jsonobj.dept_id != null && jsonobj.dept_name != null) {
          this.form.c_name = jsonobj.dept_name;
          this.form.dept_id = jsonobj.dept_id;
          this.form.state_id = '1';
          this.form.is_Recycle = '1';
          this.show_ds = true;
          this.CustomerAdd = true;
          this.CustomerEdie = false;
          this.IsDisabled = false;
          this.FindOption_show = false;
        }
        //console.log(jsonobj)
      }


      //加载 订单合同发货信息 合同性质
      if (window['contractNatureOption'] != undefined && window['contractNatureOption'] != null && window['contractNatureOption'] != '') {
        this.contractNatureOption = window['contractNatureOption'];
      } else {
        this.getDicts("contract_nature").then(response => {
          window['contractNatureOption'] = response.data;
          this.contractNatureOption = window['contractNatureOption'];
        });
      }

      //加载 发货状态
      if (window['ShipStateOption'] != undefined && window['ShipStateOption'] != null && window['ShipStateOption'] != '') {
        this.ShipStateOption = window['ShipStateOption'];
      } else {
        this.getDicts("Ship_state").then(response => {
          window['ShipStateOption'] = response.data;
          this.ShipStateOption = window['ShipStateOption'];
        });
      }


      //加载 发货类型
      if (window['DeliveryTypeOption'] != undefined && window['DeliveryTypeOption'] != null && window['DeliveryTypeOption'] != '') {
        this.DeliveryTypeOption = window['DeliveryTypeOption'];
      } else {
        this.getDicts("Delivery_type").then(response => {
          window['DeliveryTypeOption'] = response.data;
          this.DeliveryTypeOption = window['DeliveryTypeOption'];
        });
      }

      //加载 发货选择类型
      if (window['DeliverySelectionTypeOption'] != undefined && window['DeliverySelectionTypeOption'] != null && window['DeliverySelectionTypeOption'] != '') {
        this.DeliverySelectionTypeOption = window['DeliverySelectionTypeOption'];
      } else {
        this.getDicts("Delivery_selection_type").then(response => {
          window['DeliverySelectionTypeOption'] = response.data;
          this.DeliverySelectionTypeOption = window['DeliverySelectionTypeOption'];
        });
      }



      //加载 发货方式
      if (window['DeliveryMethodOption'] != undefined && window['DeliveryMethodOption'] != null && window['DeliveryMethodOption'] != '') {
        this.DeliveryMethodOption = window['DeliveryMethodOption'];
      } else {
        this.getDicts("Delivery_method").then(response => {
          window['DeliveryMethodOption'] = response.data;
          this.DeliveryMethodOption = window['DeliveryMethodOption'];
        });
      }

      //加载 运费方式
      if (window['ShippingMethodOption'] != undefined && window['ShippingMethodOption'] != null && window['ShippingMethodOption'] != '') {
        this.ShippingMethodOption = window['ShippingMethodOption'];
      } else {
        this.getDicts("Shipping_method").then(response => {
          window['ShippingMethodOption'] = response.data;
          this.ShippingMethodOption = window['ShippingMethodOption'];
        });
      }


      //加载 查询条件
      if (window['ShippingApplicationSelType'] != undefined && window['ShippingApplicationSelType'] != null && window['ShippingApplicationSelType'] != '') {
        this.typeOptions = window['ShippingApplicationSelType'];
      } else {
        this.getDicts("yunze_ShippingApplication_selType").then(response => {
          window['ShippingApplicationSelType'] = response.data;
          this.typeOptions = window['ShippingApplicationSelType'];
        });
      }

      //加载 查询时间类型 条件
      if (window['ShippingApplication_timetype'] != undefined && window['ShippingApplication_timetype'] != null && window['ShippingApplication_timetype'] != '') {
        this.timetypeOptions = window['ShippingApplication_timetype'];
      } else {
        this.getDicts("yunze_ShippingApplication_timetype").then(response => {
          window['ShippingApplication_timetype'] = response.data;
          this.timetypeOptions = window['ShippingApplication_timetype'];
        });
      }

      //加载 客户一级分类
      if (window['CustomerOneCategoryOption'] != undefined && window['CustomerOneCategoryOption'] != null && window['CustomerOneCategoryOption'] != '') {
        this.CustomerOneCategoryOption = window['CustomerOneCategoryOption'];
      } else {
        this.getDicts("yz_customer_grade_one").then(response => {
          window['CustomerOneCategoryOption'] = response.data;
          this.CustomerOneCategoryOption = window['CustomerOneCategoryOption'];
        });
      }


      //加载 客户二级分类
      if (window['CustomerTowCategoryOption'] != undefined && window['CustomerTowCategoryOption'] != null && window['CustomerTowCategoryOption'] != '') {
        this.CustomerTowCategoryOption = window['CustomerTowCategoryOption'];
      } else {
        this.getDicts("yz_customer_grade_tow").then(response => {
          window['CustomerTowCategoryOption'] = response.data;
          this.CustomerTowCategoryOption = window['CustomerTowCategoryOption'];
        });
      }


      //加载 客户 级别
      if (window['CustomerGradeOption'] != undefined && window['CustomerGradeOption'] != null && window['CustomerGradeOption'] != '') {
        this.CustomerGradeOption = window['CustomerGradeOption'];
      } else {
        this.getDicts("yz_customer_grade").then(response => {
          window['CustomerGradeOption'] = response.data;
          this.CustomerGradeOption = window['CustomerGradeOption'];
        });
      }

      //加载 客户 来源
      if (window['CustomerSourceOptions'] != undefined && window['CustomerSourceOptions'] != null && window['CustomerSourceOptions'] != '') {
        this.CustomerSourceOptions = window['CustomerSourceOptions'];
      } else {
        this.getDicts("yz_customer_source").then(response => {
          window['CustomerSourceOptions'] = response.data;
          this.CustomerSourceOptions = window['CustomerSourceOptions'];
        });
      }



      //加载 快递公司信息
      if (window['CourierCompanyOptions'] != undefined && window['CourierCompanyOptions'] != null && window['CourierCompanyOptions'] != '') {
        this.CourierCompanyOptions = window['CourierCompanyOptions'];
        this.form.SAN_Express_Delivery = this.CourierCompanyOptions[0].EDY_ID;
      } else {
        ExpressSelDate(tools.encrypt(JSON.stringify({}))).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          window['CourierCompanyOptions'] = jsonobj.Data;
          this.CourierCompanyOptions = window['CourierCompanyOptions'];
          this.form.SAN_Express_Delivery = this.CourierCompanyOptions[0].EDY_ID;
        });
      }






      //加载 大分类
      if(window['Large_classification']!=undefined &&  window['Large_classification']!=null && window['Large_classification']!=''){
        this.Large_classification = window['Large_classification'];
        let map ={};
        map.Cy_Sort = '9';
        if(tools.Is_null(window['details_'+map.Cy_Sort])){
          this.getTowClass({'Cy_Sort':window['details_'+map.Cy_Sort]});
        }
        this.commodity.Cy_Sort = this.Large_classification[0].CODE;
      }else{
        let map ={};
        map.Cy_Sort = '9';
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        Administration(Pwd_Str).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          window['Large_classification'] = jsonobj.Data;
          this.Large_classification = window['Large_classification'];
          if(this.Large_classification!=null && this.Large_classification.length>0){
            let val = '';
            for (let i = 0; i < this.Large_classification.length; i++) {
              let obj = this.Large_classification[i];
              // console.log(obj)
              window['child_id_'+map.Cy_Sort+"_"+obj.CODE] = [];
              (window['child_id_'+map.Cy_Sort+"_"+obj.CODE]).push(obj.child_id);
              if(i==0){
                window['details_'+map.Cy_Sort]= obj.child_id;
              }
            }
            if(tools.Is_null(window['details_'+map.Cy_Sort])){
              this.getTowClass({'Cy_Sort':window['details_'+map.Cy_Sort]});
              this.commodity.Cy_Sort = this.Large_classification[0].CODE;
            }
          }
        });
      }


      //加载  总部门所有人
      if(window['HeadquartersOption']!=undefined &&  window['HeadquartersOption']!=null && window['HeadquartersOption']!=''){
        this.HeadquartersOption = window['HeadquartersOption'];
        this.SetHeadquartersOption();

      }else{
        let map = {};
        map.isdept_id = 100;
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        findSalesPartner(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          if (jsonobj.code == 200) {
            window['HeadquartersOption'] = jsonobj.Data;
            this.HeadquartersOption = window['HeadquartersOption'];
            this.SetHeadquartersOption();
          }else{
            this.msgError(jsonobj.msg);
          }
        })
      }

      //条件查询 默认选择第一个
      this.queryParams.type = '1';

      // this.getTreeselect();
      //tools.Element_edit();

    },
    methods: {


      //过滤 Btns 权限 是否允许查看 全部发货申请数据
      Sales_execution(){
        let username = tools.getCookie("username");
        //console.log(username)
        if(username!='admin'){

          if(this.HeadquartersnOrmalOption!=null && this.HeadquartersnOrmalOption.length>0){
            let HeadquartersnOrmalOption = JSON.parse(JSON.stringify(this.HeadquartersnOrmalOption));
            this.create_UserIdOption = [];
            for (let i = 0; i < HeadquartersnOrmalOption.length; i++) {
              let Obj = HeadquartersnOrmalOption[i];
              if (Obj.user_name == username) {
                let arr = [];
                if(Obj.Btns!=null && Obj.Btns.indexOf(',')!=-1){
                  arr = Obj.Btns.split(",");
                }else{
                  arr = [Obj.Btns]
                }
                //console.log(arr)
                if(!tools.VerificationValIsArray(arr,"yunze:sys:ShipmentApplicationSelAll")){
                  this.create_UserIdOption.push(Obj);
                  this.queryParams.create_UserIdArr = [Obj.user_id];
                  this.clearableBool = true;
                }else{
                  this.create_UserIdOption = HeadquartersnOrmalOption;
                }
                break;
              }
            }
          }
          this.getList();
        }else{
          this.create_UserIdOption =  JSON.parse(JSON.stringify(this.HeadquartersnOrmalOption));
          this.getList();
        }
      },


      //设置管理员 选项
      SetHeadquartersOption(){

        if(this.HeadquartersOption!=null && this.HeadquartersOption.length>0){
          this.HeadquartersnOrmalOption = [];
          let username = tools.getCookie("username");
          //console.log(this.HeadquartersOption)
          for (let i = 0; i < this.HeadquartersOption.length; i++) {
            let Obj = this.HeadquartersOption[i];
            if(Obj.del_flag=='0' && Obj.status=='0'){//获取 未删除的 状态正常的
              this.HeadquartersnOrmalOption.push(Obj);
              //选中当前登录用户信息
              //console.log(username == Obj.user_name);
              if (Obj.user_name == username) {
                this.form.SAN_UserID = Obj.user_id;
              }
            }
          }
          this.Sales_execution();//过滤 Btns 权限 是否允许查看 全部发货申请数据
        }
      },


      //重置form
      ResetForm(){

      },


      //设置数据
      SetObj(Key,obj){
        //console.log(obj);
        switch (Key) {
          case 'SetEditexecute':
            this.Editexecute = obj;//设置 发货申请 编辑  是否已经加载 [提供给子组件使用]
            break;
          case 'Setform':
            this.form = obj;// 设置 form
            break;
          case 'SetRegform':
            this.Regform =obj;//发货登记
            break;
          case 'Setdrawer':
            this.show_ds = obj;// 设置 drawer
            break;
          case 'SetdrawerA':
            this.show_ds_Register = obj;// 设置 drawer
            break;
        }
      },








//获取二级分类
      getTowClass(map){
       // console.log(map)
        //加载 大分类
        if(window['TowClass'+map.Cy_Sort]!=undefined &&  window['TowClass'+map.Cy_Sort]!=null && window['TowClass'+map.Cy_Sort]!=''){
          this.Small_classification = window['TowClass'+map.Cy_Sort];
          this.commodity.Cy_Category = this.Small_classification[0].CODE;
        }else{
          let Pwd_Str = tools.encrypt(JSON.stringify(map));
          Administration(Pwd_Str).then(response => {
            let jsonobj =  JSON.parse(tools.Decrypt(response));
            window['TowClass'+map.Cy_Sort] = jsonobj.Data;
            window['TowClasschildArr'+map.child_id_sel] = window['TowClass'+map.Cy_Sort];
            //console.log(jsonobj.Data)
            this.Small_classification = window['TowClass'+map.Cy_Sort]
            this.commodity.Cy_Category = this.Small_classification[0].CODE;
          });
        }
      },


      //新增发货申请提交
      SubAdd(map) {
        console.log(map)
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        add(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.msgSuccess(jsonobj.msg);
            this.show_ds =false;
            //更新数据
            this.queryParams.page = 1;
            this.getList();
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        })
      },


      //修改 发货申请提交
      SubUpd(map) {
        //console.log(map)
       let Pwd_Str = tools.encrypt(JSON.stringify(map));
        Updinfo(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.msgSuccess(jsonobj.msg);
            this.show_ds =false;
            //更新数据
            this.queryParams.page = 1;
            this.getList();
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        })
      },





      // 发货申请 登记 （快递新增）
      SubRegister(map) {
        //console.log(map)
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        Register(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.msgSuccess(jsonobj.msg);
            this.show_ds_Register =false;
            //更新数据
            this.queryParams.page = 1;
            this.getList();
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        })
      },









      //获取对应 class 颜色
      getColor(key){
        var class_color="";
        switch (key) {
          case 1:
            class_color='my_cloor_red';
            break;
          case 2:
            class_color='my_cloor_blue';
            break;
          default:
            class_color='my_cloor_black';
            break;
        }
        return class_color;
      },

      /*获取查询参数*/
      getParams() {
        if (tools.Is_null(this.queryParams.timetype) && this.selTime != null) {
          this.queryParams.staTime = this.selTime[0];
          this.queryParams.endTime = this.selTime[1];
        }


        //console.log(this.queryParams);
      },


      /** 查询通道列表 */
      getList() {
        this.loading = true;
        this.getParams();
        this.queryParams.page = 1;
        let Pwd_Str = tools.encrypt(JSON.stringify(this.queryParams));
        getList(Pwd_Str).then(response => {
            let jsonobj = JSON.parse(tools.Decrypt(response));
            if (jsonobj.code == 200) {
              //console.log(jsonobj)
              this.DataList = jsonobj.Data.Data;
              this.total = jsonobj.Data.Pu.rowCount;
            } else {
              this.msgError(jsonobj.msg);
            }
            this.loading = false;
          }
        );
      },
      /*代理查询拓展*/
      agentShow() {
        let _this = this;
        _this.option_show = !_this.option_show;
        _this.mainwidth = _this.option_show ? 20 : 24;
      },


      // 取消按钮
      cancel() {
        this.open = false;
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams = {};
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        this.selTime = null;
        this.handleQuery();
      },

      /** 新增按钮操作 */
      handleAdd() {
        //this.form = {};//清空数据
        this.show_ds = true;
        this.CustomerAdd = true;
        this.CustomerEdie = false;
        this.Editexecute = true;
        this.OperationType = 'SubAdd';
      },



      /*客户信息关闭 触发 */
      DrawerClose() {
        //如果当期是 修改操作关闭界面 清空 dept_id 和 name
        if (this.CustomerEdie == true) {
          this.form.dept_id = '';
          this.form.c_name = '';
        }
        //console.log(this.CustomerEdie)
      },

      RateSetting() {

      },



      /** 修改按钮操作 */
      handleUpdate(row, Operate) {

        if(Operate == "Edit"|| Operate == "Find"){
          this.form = {
            SAN_ID: row.SAN_ID,
            SAN_StyID: null,
            SAN_CoID: null,
            SAN_CoName: null,
            SAN_Recipient_Name: null,
            SAN_Recipient_Tel: null,
            SAN_Recipient_Address: null,
            SAN_Time: tools.gitData(),
            SAN_UserID: null,
            SAN_Sender_Name: null,
            SAN_ShiptyID: null,
            SAN_FpayType: null,
            SAN_Tracking_Number: null,
            SAN_Express_Delivery: null,
            SAN_Delivery_Status: null,
            SAN_Delivery_Person: null,
            SAN_Remarks: null,
            SAN_Shipping_Method: null,
            SAN_Shipping_MethodArr: [],
            IsManual: '0',//手动填写
            IsManualBool: false,//手动填写 bool
            c_party_a_id:null,
            Manual_SAN_Recipient_Address:null,//手动填写 地址
            Manual_SAN_Recipient_Tel:null,//手动填写 收件人电话
            Manual_SAN_Recipient_Name:null,//手动填写 收件人
          };
        }else if(Operate == "Register"){
          this.Regform = {
            SAN_ID: row.SAN_ID,
            SAN_StyID: null,
            SAN_CoID: null,
            SAN_CoName: null,
            SAN_Recipient_Name: null,
            SAN_Recipient_Tel: null,
            SAN_Recipient_Address: null,
            SAN_Time: tools.gitData(),
            SAN_UserID: null,
            SAN_Sender_Name: null,
            SAN_ShiptyID: null,
            SAN_FpayType: null,
            SAN_Tracking_Number: null,
            SAN_Express_Delivery: null,
            SAN_Delivery_Status: null,
            SAN_Delivery_Person: null,
            SAN_Remarks: null,
            SAN_Shipping_Method: null,
            SAN_Shipping_MethodArr: [],
            IsManual: '0',//手动填写
            IsManualBool: false,//手动填写 bool
            c_party_a_id:null,
            Manual_SAN_Recipient_Address:null,//手动填写 地址
            Manual_SAN_Recipient_Tel:null,//手动填写 收件人电话
            Manual_SAN_Recipient_Name:null,//手动填写 收件人
          };
        }

        //清空子组件选择

        this.Editexecute = false;
        if (Operate == "Edit") {
          this.show_ds = true;
          this.CustomerAdd = false;
          this.CustomerEdie = true;
          this.OperationType = 'SubUpd';
        } else if (Operate == "Find") {
          this.show_ds = true;
          this.CustomerAdd = false;
          this.CustomerEdie = false;
        }else if(Operate == "Register"){
          this.show_ds_Register = true;
          this.CustomerAdd = false;
          this.CustomerEdie = true;
        }
      },

      //删除 发货申请 按钮点击
      handleDel(row) {
        let map = {};
        map.SAN_ID = row.SAN_ID;
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        tools.openAsk(this,'warning', "确定要删除 发货日期 '"+row.SAN_Time+"' ，企业名称 【"+row.SAN_CoName+"】   的这条数据吗？", this.delFun, Pwd_Str);
      },

      //删除 发货申请
      delFun(Pwd_Str){
        DelInfo(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.msgSuccess(jsonobj.msg);
            this.queryParams.page = 1;
            this.getList();
          }else{
            let msg = jsonobj.Data!=null && jsonobj.Data!=''?jsonobj.Data:jsonobj.msg;
            this.msgError(msg);
          }
        })
      },



      }
  };
</script>


<style scoped>
  .my_cloor_red {
    background-color: #e64242;
    color: white;
  }
  .my_cloor_blue {
     background-color: #1682e6;
     color: white;
   }
  .my_cloor_Orange {
    background-color: #303133;
    color: white;
  }
  .my_cloor_black {
    background-color: #303133;
    color: white;
  }

  .el-divider--horizontal{
    margin: 18px 0;
  }

</style>


